package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.R;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.entity.SupplierPage;
import com.atguigu.jxc.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    //分页获取供应商列表
    @PostMapping("list")
    public Map<String,Object> getSupplierList(@RequestParam("page") Integer page,
                                              @RequestParam("rows") Integer rows,
                                              @RequestParam("supplierName") String supplierName){
        SupplierPage supplierPage = new SupplierPage();
        supplierPage.setPage(page);
        supplierPage.setSupplierName(supplierName);
        supplierPage.setRows(rows);
        return supplierService.getSupplierList(supplierPage);
    }

    @PostMapping("save")
    public R save(Supplier supplier){
        int i = supplierService.saveOrUpdate(supplier);
        return R.ok(100,"保存供应商成功",null);
    }


    @PostMapping("delete")
    public R deleteById(String[] ids){
        supplierService.deleteByIds(ids);
        return R.ok(100,"删除成功",null);
    }
}
